const jwt = require('jsonwebtoken')
const { expressjwt: expressJWT } = require("express-jwt");
const secretKey = 'math&*S_er^vice+'
// 生成token
exports.createToken = (name) => {
  return "Bearer " + jwt.sign({ name }, secretKey, { expiresIn: '7200s' })
}
// 解析token
exports.expressToken = (app) => {
  app.use(expressJWT({ secret: secretKey, algorithms: ["HS256"] }).unless({ path: [/^\/server\//] }))
}
// 头像数据转换
exports.blob2String = (item) => {
  if (item.avatar) {
    const buffer = new Buffer.from(item.avatar);
    const basebuffer = buffer.toString()
    item.avatar = basebuffer
  }
}
